﻿namespace QLBanHang.Report
{
    using DevExpress.XtraPrinting;
    using DevExpress.XtraPrinting.Preview;
    using DevExpress.XtraReports.UI;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.IO;

    public class XtraReport1 : XtraReport
    {
        private string _filePath = "";
        private int _isolanin = 0;
        private BottomMarginBand BottomMargin;
        public bool bPrinting = false;
        private IContainer components = null;
        private DetailBand Detail;
        //public DevExpress.XtraReports.Parameters.Parameter parameter1;
        public DevExpress.XtraReports.Parameters.Parameter parTenCoSo;
        public DevExpress.XtraReports.Parameters.Parameter parDiaChi;
        public DevExpress.XtraReports.Parameters.Parameter parDienThoai;
        public DevExpress.XtraReports.Parameters.Parameter parEmail;
        private TopMarginBand TopMargin;

        public XtraReport1()
        {
            this.InitializeComponent();
            string[] strArray = Directory.GetCurrentDirectory().Split(new char[] { '\\' });
            for (int i = 0; i < (strArray.Length - 1); i++)
            {
                this._filePath = this._filePath + strArray[i] + @"\";
            }
            this._filePath = this._filePath + "Report";
            if (!Directory.Exists(this._filePath))
            {
                Directory.CreateDirectory(this._filePath);
            }
        }
        void f_khoitao(string LinkReportFileName)
        {
            base.LoadLayout(LinkReportFileName);
            Access.Chung.CThongSo vcts = new Access.Chung.CThongSo();
            
            parTenCoSo = new DevExpress.XtraReports.Parameters.Parameter();
            try { parTenCoSo.Value = vcts.pTenCoSo; }
            catch { parTenCoSo.Value = ""; }
            
            parDiaChi = new DevExpress.XtraReports.Parameters.Parameter();
            try { parDiaChi.Value = vcts.pDiaChi; }
            catch { parDiaChi.Value = ""; }
            
            parDienThoai = new DevExpress.XtraReports.Parameters.Parameter();
            try { parDienThoai.Value = vcts.pDienThoai; }
            catch { parDienThoai.Value = ""; }
            
            parEmail = new DevExpress.XtraReports.Parameters.Parameter();
            try { parEmail.Value = vcts.pEmail; }
            catch { parEmail.Value = ""; }

            
            base.Parameters.Add(parTenCoSo);
            base.Parameters.Add(parDienThoai);
            base.Parameters.Add(parDiaChi);
            base.Parameters.Add(parEmail);

            base.SaveLayout(LinkReportFileName);
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public void f_load(DataSet data, string fileNameReport)
        {
            string fileName = this._filePath + @"\" + fileNameReport;
            f_khoitao(fileName);
            base.LoadLayout(fileName);
            base.DataSource = data;
            if (this.bPrinting)
            {
                this.Print();
            }
            else
            {
                base.CreateDocument();
                new PrintPreviewFormEx { Text = fileNameReport, PrintingSystem = base.PrintingSystem }.ShowDialog();
            }
        }

        private void InitializeComponent()
        {
            this.Detail = new DevExpress.XtraReports.UI.DetailBand();
            this.BottomMargin = new DevExpress.XtraReports.UI.BottomMarginBand();
            this.TopMargin = new DevExpress.XtraReports.UI.TopMarginBand();
            //this.parameter1 = new DevExpress.XtraReports.Parameters.Parameter();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            // 
            // Detail
            // 
            this.Detail.Name = "Detail";
            // 
            // BottomMargin
            // 
            this.BottomMargin.Name = "BottomMargin";
            // 
            // TopMargin
            // 
            this.TopMargin.Name = "TopMargin";            
            // 
            // XtraReport1
            // 
            this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] {
            this.TopMargin,
            this.Detail,
            this.BottomMargin});
           
            this.Version = "12.2";
            this.PrintProgress += new DevExpress.XtraPrinting.PrintProgressEventHandler(this.XtraReport1_PrintProgress);
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();

        }

        private void XtraReport1_PrintProgress(object sender, PrintProgressEventArgs e)
        {
            this._isolanin++;
        }

        public int pPrintingCount
        {
            get
            {
                return this._isolanin;
            }
        }
    }
}

